<?php
/**
 * Created by PhpStorm.
 * Admin: Administrator
 * Date: 2018/6/6/006
 * Time: 9:32
 */

namespace App\Http\Controllers\Account;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Service\Account\AccountService;
use App\Http\Service\Product\ProductService;
use App\Http\Service\Order\OrderService;
use App\Http\Controllers\Controller;
use Session,Config;
use Cache;
use Excel;

class AccountDetailController extends Controller
{

    /**
     * @return view
     * 会员详情页面
     */
    public function accDetail()
    {
        $where = [];

        $Product = new ProductService();
        $data =  $Product->getTypeList($where);


        $packlist = $this->getPackageList();

        return view('Account.account_detail')->with('data',$data['data'])->with('packlist',$packlist);
    }


    /**
     * @param Request $request
     * @return bool|mixed|string
     * 用户详情
     */
    public function getAccountDetail(Request $request)
    {
        $where = $request->except('_token');
        $where['token'] = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));

        $Account = new AccountService();
        $data= $Account->getAccdetail($where);

        if($data && !empty($data['data']))
        {


            $data['data']['wechat_bind_name'] = $data['data']['wechat_bind_status'] == 1?'已绑定':'未绑定';
            $data['data']['frozen_status'] = $data['data']['frozen_flag'] == 1?'已冻结':'正常';
            $data['data']['balance'] = $data['data']['balance'] . "元";

            return $data;
        }



    }


    /**
     * @param Request $request
     * @return bool|mixed|string
     * 重置用户密码
     */
    public function resetPassword(Request $request)
    {
        $where = $request->except('_token');
        $where['token'] = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));

        unset($where['confirm_password']);

        $Account = new AccountService();
        $data = $Account->resetPassword($where);
        if($data){
            return $data;
        }


    }

    /**
     * @param Request $request
     * @return bool|mixed|string
     * 获取用户钱包流水
     */
    public function getUserWalletList(Request $request){
        $where = [];
        $token = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));

        $where= $request->except('_token');

        if($request->has('page'))
        {
            $where['page_no'] = $request->input('page');
            unset($where['page']);
        }
        if($request->has('limit'))
        {
            $where['page_size'] = $request->input('limit');
            unset($where['limit']);
        }else{
            $where['page_size'] = 10;
        }


        foreach($where as $key=>$value)
        {
            if($value =='' || $value == 'undefined')
            {
                unset($where[$key]);
            }
        }

        $where['token'] = $token;

        $Order = new OrderService();
        $data = $Order->getUserWalletList($where);
        if($data){
            return $data;
        }


    }

    /**
     * @param Request $request
     * @return bool|mixed|string
     * 获取用户时长套餐列表
     */
    public function getUserSetMealTimeList(Request $request){
        $where = [];
        $token = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));

        $where= $request->except('_token');

        if($request->has('page'))
        {
            $where['page_no'] = $request->input('page');
            unset($where['page']);
        }
        if($request->has('limit'))
        {
            $where['page_size'] = $request->input('limit');
            unset($where['limit']);
        }else{
            $where['page_size'] = 10;
        }


        foreach($where as $key=>$value)
        {
            if($value =='' || $value == 'undefined')
            {
                unset($where[$key]);
            }
        }

        $where['token'] = $token;

        $Order = new AccountService();
        $data = $Order->getMemberSetMealTime($where);
        if($data){
            return $data;
        }


    }

    /**
     * @param Request $request
     * @return bool|mixed|string
     * 获取用户包量套餐列表
     */
    public function getUserSetMealNumList(Request $request){
        $where = [];
        $token = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));

        $where= $request->except('_token');

        if($request->has('page'))
        {
            $where['page_no'] = $request->input('page');
            unset($where['page']);
        }
        if($request->has('limit'))
        {
            $where['page_size'] = $request->input('limit');
            unset($where['limit']);
        }else{
            $where['page_size'] = 10;
        }


        foreach($where as $key=>$value)
        {
            if($value =='' || $value == 'undefined')
            {
                unset($where[$key]);
            }
        }

        $where['token'] = $token;


        $Order = new AccountService();
        $data = $Order->getMemberSetMealNumber($where);
        if($data){
            return $data;
        }


    }


    public function renewSetMeal(Request $request)
    {
        $where = $request->except('_token');

        $where['token'] = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));

        $Account = new AccountService();
        $data = $Account->renewSetMeal($where);

        if($data){
            return $data;
        }


    }


    public function updateSetMeal(Request $request)
    {
        $where = $request->except('_token');

        $where['token'] = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));

        $Account = new AccountService();
        $data = $Account->updateSetMeal($where);

        if($data){
            return $data;
        }


    }


    public function addSetMeal(Request $request)
    {
        $where = $request->except('_token');

        $where['token'] = Session::get(Config::get('custom.setting.MEMBER_TOKEN'));

        $Account = new AccountService();
        $data = $Account->addSetMeal($where);

        if($data){
            return $data;
        }


    }

    public function getPackageList(){
        $where = [];
        $product = new ProductService();
        $data = $product->getProductInfoList($where);

        if($data['error_code'] == 0)
        {
            $ret = $data['data'];
        } else {
            $ret = [];
        }
        return $ret;
    }


}